<template>
	<view class="">
		
	</view>
</template>

<script>
	import api from "@/utils/api.js"
	import request from "@/utils/request.js"
	export default {
		data() {
			return {
				title: ''
			}
		},
		// created() {
		// 	console.log(111)
		// 	const code = getUrlParam('code');
		// 	console.log(code)
		// },
		// onLoad() {
		// 	console.log(222)
		// 	const code = getUrlParam('code');
		// 	console.log(code)
		// 	this.getTokenApi(code)
		// },
		onShow() {
			console.log(333)
			const code = this.getUrlParam('code');
			console.log('code-----',code)
			this.getTokenApi(code)
		},
		methods: {
			// 获取token的接口方法
			getTokenApi(code) {
				console.log(code,'---------code')

				let data = {
					code: code
				}
				request(api.checkLogin, 'GET', data)
					.then(res => {
						console.log('getTokenApi数据:', res.data);
						if (res.code == 200) {
							uni.setStorageSync('wxwork_token', res.data) //token数据存本地
							const jumpUrl = uni.getStorageSync('jumpUrl');
							console.log(jumpUrl, 'jumpUrl');
							uni.redirectTo({
								url: jumpUrl
							})
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
							});
							setTimeout(()=>{
								uni.reLaunch({
									url:'/pages/index/index'
								})								
							},1300)
						}
					})
					.catch(response => {
						console.log('response',response)
						uni.showToast({
							title: response,
							icon: "none",
						});
						setTimeout(()=>{
							uni.reLaunch({
								url:'/pages/index/index'
							})								
						},1300)
					})
					

			},
			getUrlParam(paramName, url = window.location.href) {
				try {
					const urlObj = new URL(url);
					return urlObj.searchParams.get(paramName);
				} catch (e) {
					// URL解析失败时使用正则表达式作为降级方案
					const regex = new RegExp(`[?&]${paramName}=([^&]*)`);
					const match = url.match(regex);
					return match ? decodeURIComponent(match[1]) : null;
				}
			}


		}
	}
</script>

<style>
</style>